.POSIX:
PREFIX=		/usr/local
MANDIR=		man

SRC=		auplayer.c playlist.c util.c
HDR=		playlist.h util.h

default:
	@if grep -q pledge /usr/include/unistd.h; then		\
		export CFLAGS="$$CFLAGS -DUSE_PLEDGE";		\
	fi;							\
	case "$$(uname | tr '[:upper:]' '[:lower:]')" in	\
	*sunos*|*netbsd*)	AUDEV='exec au2audio';;		\
	*openbsd*)		AUDEV='exec au2sndio';;		\
	*freebsd*)		AUDEV='exec au2oss';;		\
	*)			AUDEV='exec au2sdl';;		\
	esac;							\
	export CFLAGS="$$CFLAGS -DAUDEV_DEFAULT='\"$$AUDEV\"'";	\
	${MAKE} ${MAKEFLAGS} auplayer
all: default README
install: default
	${INSTALL} -m 755 auplayer ${DESTDIR}${PREFIX}/bin/
	${INSTALL} -m 444 auplayer.1 ${DESTDIR}${PREFIX}/${MANDIR}/man1/
install-local: default
	${INSTALL} -m 755 auplayer ${HOME}/bin/
auplayer: ${SRC} ${HDR} Makefile
	${CC} ${CFLAGS} ${LDFLAGS} -o $@ ${SRC}
README: auplayer.1 Makefile
	mandoc -Ios= -Tutf8 auplayer.1 |\
	    awk '{gsub(/.\b/,"");a=b;b=c;c=$$0}FNR>4{print a}' > $@
clean:
	rm -f auplayer
clean-all: clean
	rm -f README
